// 基于template/src/router/routes/view-route.ts.hbs生成
import qs from 'qs';
import AuthGuard from '../guard/auth-guard';
import { EntityRoute } from './entity-route';
import { userIndexRoute, userViewRoute } from './user-route';

const viewRoute = [
    {
        path: '/index/:index?',
        name: 'index',
        meta: {
            caption: '演示应用',
            tag: 'index',
            requireAuth: false,
            ignoreAddPage: false,
            startPage: true,
            parameters: [
                { pathName: 'views', parameterName: 'index' },
            ],
        },
        beforeEnter: (to: any, from: any, next: any) => {
            to.defaultPage = true;
            const routerParamsName = 'index';
            const params: any = {};
            if (to.params && to.params[routerParamsName]) {
                Object.assign(params, qs.parse(to.params[routerParamsName], { delimiter: ';' }));
            }
            const url: string = '/appdata';
            const auth: Promise<any> = AuthGuard.getInstance().authGuard(url, params);
            auth.then((result: any) => {
                next(result ? true : false);
            }).catch(() => {
                next(false);
            })
        },
        component: () => import("@views/index/index.vue"),
        children: [
            {
                path: 'views/appportalview2',
                meta: {
                    caption: '门户部件',
                    captionLanResTag: 'MENUITEM.CAPTION.PORTALCOMPONENTS',                    
                    tag: 'AppPortalView2',
                    requireAuth: false,
                    ignoreAddPage: false,
                    startPage: false,
                    accessKey:'',
                    accUserMode:0,
                    parameters: [
                        { pathName: 'views', parameterName: 'index' },
                    ],
                },
                component: () => import("@views/app-portal-view-2/app-portal-view-2.vue"),
            },
            {
                path: 'views/portal',
                meta: {
                    caption: '',
                    captionLanResTag: '',                    
                    tag: 'portal',
                    requireAuth: false,
                    ignoreAddPage: false,
                    startPage: false,
                    accessKey:'',
                    accUserMode:2,
                    parameters: [
                        { pathName: 'views', parameterName: 'index' },
                    ],
                },
                component: () => import("@views/portal/portal.vue"),
            },
            {
                path: 'views/apppanelview',
                meta: {
                    caption: '',
                    captionLanResTag: '',                    
                    tag: 'AppPanelView',
                    requireAuth: false,
                    ignoreAddPage: false,
                    startPage: false,
                    accessKey:'',
                    accUserMode:0,
                    parameters: [
                        { pathName: 'views', parameterName: 'index' },
                    ],
                },
                component: () => import("@views/app-panel-view/app-panel-view.vue"),
            },
            {
                path: 'views/appindexview',
                meta: {
                    caption: '测试12231',
                    captionLanResTag: 'PAGE.CAPTION.WEB.APPINDEXVIEW',
                    tag: 'AppIndexView',
                    requireAuth: false,
                    ignoreAddPage: false,
                    startPage: false,
                    accessKey:'',
                    accUserMode:0,
                    parameters: [
                        { pathName: 'views', parameterName: 'index' },
                    ],
                },
                component: () => import("@views/app-index-view/app-index-view.vue"),
            },
            {
                path: 'appwfdataredirectview/:appwfdataredirectview?',
                meta: {
                    caption: '应用全局流程工作重定向视图',
                    captionLanResTag: '',                    
                    tag: 'AppWFRedirectView',
                    requireAuth: false,
                    ignoreAddPage: false,
                    startPage: false,
                    parameters: [
                        { pathName: 'views', parameterName: 'index' },
                    ],
                },
                component: () => import("@views/app-wf-redirect-view/app-wf-redirect-view.vue"),
            },
            {
                path: 'views/apppanelview2',
                meta: {
                    caption: '工作流待办',
                    captionLanResTag: '',                    
                    tag: 'AppPanelView2',
                    requireAuth: false,
                    ignoreAddPage: false,
                    startPage: false,
                    accessKey:'',
                    accUserMode:0,
                    parameters: [
                        { pathName: 'views', parameterName: 'index' },
                    ],
                },
                component: () => import("@views/app-panel-view-2/app-panel-view-2.vue"),
            },
            {
                path: 'views/appportalview',
                meta: {
                    caption: '工作台',
                    captionLanResTag: 'MENUITEM.CAPTION.WORKBENCH',                    
                    tag: 'AppPortalView',
                    requireAuth: false,
                    ignoreAddPage: false,
                    startPage: false,
                    accessKey:'',
                    accUserMode:0,
                    parameters: [
                        { pathName: 'views', parameterName: 'index' },
                    ],
                },
                component: () => import("@views/app-portal-view/app-portal-view.vue"),
            },
            {
                path: 'views/appindexview2',
                meta: {
                    caption: '测试首页',
                    captionLanResTag: '',
                    tag: 'AppIndexView2',
                    requireAuth: false,
                    ignoreAddPage: false,
                    startPage: false,
                    accessKey:'',
                    accUserMode:0,
                    parameters: [
                        { pathName: 'views', parameterName: 'index' },
                    ],
                },
                component: () => import("@views/app-index-view-2/app-index-view-2.vue"),
            },
            {
                path: '/appredirectview',
                meta: {
                    caption: '全局应用重定向视图',
                    tag: 'AppRedirectView',
                    requireAuth: false,
                    ignoreAddPage: true,
                    startPage: false,
                    parameters: [
                        { pathName: 'appredirectview', parameterName: 'appredirectview' },
                        { pathName: 'views', parameterName: 'view' }
                    ],
                },
                //  component: () => import('@components/app-redirect-view/app-redirect-view.vue')
            },
            {
                path: 'apphtmlview/:apphtmlview?',
                meta: {
                    caption: '应用HTML视图',
                    tag: 'AppHtmlView',
                    requireAuth: false,
                    ignoreAddPage: false,
                    startPage: false,
                    parameters: [
                      { pathName: 'apphtmlview', parameterName: 'apphtmlview' },
                      { pathName: 'views', parameterName: 'view' },
                    ],
                },
                component: () => import('@components/function/html-container/src/html-container.vue'),
            },
            ...EntityRoute,
            ...userViewRoute,
        ]
    },
    {
        path: '/login/:login?',
        name: 'login',
        meta: {
            caption: '登录',
            tag: 'AppLoginView',
            requireAuth: false,
            ignoreAddPage: true,
            startPage: false
        },
        component: () => import('@components/function/login/src/login.vue')
    },
    {
        path: '/404',
        meta: {
            caption: '404',
            tag: 'AppNotFoundView',
            ignoreAddPage: true,
            requireAuth: false,
            startPage: false
        },
        component: () => import('@components/function/404/src/404.vue'),
    },
    {
        path: '/401',
        meta: {
            caption: '401',
            tag: 'AppNotAuthView',
            ignoreAddPage: true,
            requireAuth: false,
            startPage: false
        },
        component: () => import('@components/function/401/src/401.vue'),
    },
    {
        path: '/500',
        meta: {
            caption: '500',
            tag: 'AppErrorView',
            ignoreAddPage: true,
            requireAuth: false,
            startPage: false
        },
        component: () => import('@components/function/500/src/500.vue'),
    },
    {
        path: '/lock',
        meta: {
            caption: 'lock',
            tag: 'AppLockView',
            ignoreAddPage: true,
            requireAuth: false,
            startPage: false
        },
        component: () => import('@components/function/lock/src/lock.vue'),
    },
    ...userIndexRoute
]

export const ViewRoute = viewRoute;